package cn.wolfcode.business.controller;


import cn.wolfcode.business.domain.BusServiceItem;
import cn.wolfcode.business.domain.vo.AduitVo;
import cn.wolfcode.business.service.BusServiceItemService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.wolfcode.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/business/serviceltem")
//手写的controller需要继承BaseController
public class BusServiceItemController extends BaseController {

    @Autowired
    BusServiceItemService busServiceItemService;

    /**
     * 获取服务项列表--具有分页所以他的返回值类型为  TableDataInfo
     * 传递参数用于高级查询的条件
     */
    @GetMapping("/list")
    public TableDataInfo getList(BusServiceItem busServiceItem) {
        startPage();
        List<BusServiceItem> list = busServiceItemService.getList(busServiceItem);
        return getDataTable(list);
    }

    /**
     * 在明细页面获取服务项列表
     * 传递参数用于高级查询的条件
     */
    @GetMapping(value = "/list", headers = "cmd=list")
    public AjaxResult getListDetil(BusServiceItem busServiceItem) {
        List<BusServiceItem> list = busServiceItemService.getList(busServiceItem);
        return AjaxResult.success(list);
    }

    /**
     * 根据插入的参数查询到一条服务项数据，用于回显页面
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getBusServiceItem(@PathVariable Long id) {
        return AjaxResult.success(busServiceItemService.getBusServiceItem(id));
    }

    /**
     * 新增服务项
     *
     * @param busServiceItem
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody BusServiceItem busServiceItem) {
        return AjaxResult.success(busServiceItemService.add(busServiceItem));
    }

    /**
     * 编辑服务项信息
     *
     * @param busServiceItem
     * @return
     */
    @PutMapping
    public AjaxResult update(@RequestBody BusServiceItem busServiceItem) {
        return AjaxResult.success(busServiceItemService.update(busServiceItem));
    }

    /**
     * 上架功能
     *
     * @param id
     * @return
     */
    @PatchMapping(value = "/{id}", headers = "cmd=puton")
    public AjaxResult puton(@PathVariable Long id) {
        return AjaxResult.success(busServiceItemService.puton(id));
    }

    /**
     * 下架功能
     *
     * @param id
     * @return
     */
    @PatchMapping(value = "/{id}", headers = "cmd=putoff")
    public AjaxResult putoff(@PathVariable("id") Long id) {
        return AjaxResult.success(busServiceItemService.putoff(id));
    }

    /**
     * 发起审核前的数据回显，接收一个服务项id
     * 返回服务项的 服务项名称，原价，折扣价
     * 店长列表
     * 财务列表
     * 阈值
     */
    @GetMapping("/{id}/startAudit")
    public AjaxResult startAudit(@PathVariable Long id) {
        return AjaxResult.success(busServiceItemService.startAudit(id));
    }
    /**
     * 发起服务项审核
     */
    @PostMapping("/startAuditSubmit")
    public AjaxResult startAuditSubmit(@RequestBody AduitVo aduitVo ){
      return  AjaxResult.success(busServiceItemService.startAuditSubmit(aduitVo));
    }
}
